<template>
	<view>
		<view class="navBar">
			<view class="left">
				<uni-icons type="left" size="24" @click="toBack"></uni-icons>
			</view>
			<view class="center">我的订单</view>
			<view class="right"></view>
		</view>
		<view class="order-items">
			<view v-for="(order, index) in orderList" :key="index" class="order-item" @click="toOrder(order.orderId)">
				<view class="info">
					<view>订单ID：{{ order.orderId }}</view>
					<view>总价：￥{{ order.totalPrice }}</view>
					<view>
						<view>创建时间：</view>
						<view>{{ order.creatTime }}</view>
					</view>
					<view>支付状态：{{ order.paymentStatus }}</view>
				</view>
			</view>
		</view>
		<view class="foot"></view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				orderList: [],
			}
		},
		onLoad() {
			this.getOrderList();
		},
		onPullDownRefresh() {
			this.getOrderList();
		},
		methods: {
			toBack() {
				uni.navigateBack({
					delta: 1
				});
			},
			getOrderList() {
				uni.request({
					url: 'http://localhost:8080/order/findOrderByUserId',
					method: 'GET',
					data: {
						token: uni.getStorageSync("token")
					},
					success: res => {
						if (res.data) {
							this.orderList = res.data;
							this.orderList.forEach(item=>{
								if(item.paymentStatus=="fail"){
									item.paymentStatus="未支付";
								}else if(item.paymentStatus=="success"){
									item.paymentStatus="已支付";
								}
							})
						} else{
							uni.showToast({
								icon:"none",
								title:"登录过期，重新登录"
							})
						}
						uni.stopPullDownRefresh();
					},
					fail: () => {},
					complete: () => {}
				});
			},
			toOrder(orderId){
				uni.navigateTo({
					url: '/pages/order/order?orderId='+orderId,
				});
			}
		}
	}
</script>

<style lang="scss">
	.navBar {
		display: flex;
		height: 100rpx;
		background-color: white;
		align-items: center;
		padding: 0 30rpx;
		/* #ifdef MP-WEIXIN */
		padding-top: 100rpx;
		/* #endif */

		.left {
			flex: 1;
		}

		.center {
			flex: 1;
			color: #646566;
			text-align: center;
			font-size: 34rpx;
			font-weight: 700;
		}

		.right {
			flex: 1;
		}
	}

	// .order-item {
	//   // 单个订单样式
	//   margin-bottom: 20rpx;
	//   padding: 20rpx;
	//   background-color: #f2f2f2;
	// }
	.order-items {
		margin: 40rpx;
		font-size: 32rpx;
		color: #333;

		.order-item {
			margin-top: 20rpx;
			padding: 20rpx;
			border: 2rpx solid #ddd;
			background-color: white;
			border-radius: 25rpx;

			>view {
				margin-bottom: 10px;
			}
		}

	}
	.foot{
		height: 20rpx;
	}
</style>